package com.freeter.modules.user.controller;

import java.util.Arrays;

import com.freeter.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.freeter.common.utils.JQPageInfo;
import com.freeter.common.mpextend.parser.ParseWrapper;
import com.freeter.common.utils.PageInfo;


import com.freeter.modules.user.entity.UserAuthsEntity;
import com.freeter.modules.user.entity.view.UserAuthsView;
import com.freeter.modules.user.entity.model.UserAuthsModel;

import com.freeter.modules.user.service.UserAuthsService;
import com.freeter.common.utils.PageUtils;
import com.freeter.common.utils.R;
import com.freeter.common.utils.MPUtil;



/**
 * 用户授权表
 * 后端接口
 * @author xuchen
 * @email 171998110@qq.com
 * @date 2019-04-07 16:11:14
 */
@RestController
@RequestMapping("user/userauths")
@SuppressWarnings({"unchecked","rawtypes"})
public class UserAuthsController {
    @Autowired
    private UserAuthsService userAuthsService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    @RequiresPermissions("user:userauths:list")
    public PageUtils page(JQPageInfo jqPageInfo,UserAuthsModel userAuths){
        EntityWrapper< UserAuthsEntity> ew = ParseWrapper.parseWrapper(userAuths);
     	PageInfo pageInfo = new PageInfo(jqPageInfo);
     	PageUtils page = userAuthsService.queryPage(pageInfo, ew);
    
        return page;
        
    }

	/**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("user:userauths:list")
    public R list( UserAuthsModel userAuths){
       	EntityWrapper< UserAuthsEntity> ew = ParseWrapper.parseWrapper(userAuths);
        return R.ok().put("data",  userAuthsService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    @RequiresPermissions("user:userauths:info")
    public R query(UserAuthsEntity userAuths){
        EntityWrapper< UserAuthsEntity> ew = ParseWrapper.parseWrapper(userAuths);
		UserAuthsView  userAuthsView =  userAuthsService.selectView(ew);
		return R.ok("查询用户授权表成功").put("data",  userAuthsView);
    }
	
    /**
     * 信息
     */
    @RequestMapping("/info/{identifier}")
    @RequiresPermissions("user:userauths:info")
    public R info(@PathVariable("identifier") String identifier){
        UserAuthsEntity userAuths = userAuthsService.selectById(identifier);

        return R.ok().put("userAuths", userAuths);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("user:userauths:save")
    public R save(@RequestBody UserAuthsEntity userAuths){
    	ValidatorUtils.validateEntity(userAuths);
        userAuthsService.insert(userAuths);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("user:userauths:update")
    public R update(@RequestBody UserAuthsEntity userAuths){
        ValidatorUtils.validateEntity(userAuths);
        userAuthsService.updateAllColumnById(userAuths);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("user:userauths:delete")
    public R delete(@RequestBody String[] identifiers){
        userAuthsService.deleteBatchIds(Arrays.asList(identifiers));

        return R.ok();
    }

}
